﻿using System;
using System.Globalization;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace YFIN.View.Helper
{
    public class DateTimeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType,
        object parameter, CultureInfo language)
        {
            return ((DateTime) value).ToString("yyyy-MM-dd HH:mm");
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, CultureInfo language)
        {
            return DateTime.Parse((string)value);
        }
    }
    public class DateConverter : IValueConverter
    {
        public object Convert(object value, Type targetType,
        object parameter, CultureInfo language)
        {
            return ((DateTime) value).ToString("yyyy-MM-dd");
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, CultureInfo language)
        {
            return DateTime.Parse((string)value);
        }
    }

    public class BoolToBoldConverter : IValueConverter
    {
        public object Convert(object value, Type targetType,
        object parameter, CultureInfo language)
        {
            return (bool)value ? "Bold" : "Normal";
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, CultureInfo language)
        {
            throw new NotImplementedException();
        }
    }

    public class BoolToColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType,
        object parameter, CultureInfo language)
        {
            return (bool)value ? "#FFF1A95E" : "Black";
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, CultureInfo language)
        {
            throw new NotImplementedException();
        }
    }

    public class BenefitTypeToStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType,
        object parameter, CultureInfo language)
        {
            string res;
            switch ((byte?)value)
            {
                case 0:
                    res = "保本保收益";
                    break;
                case 1:
                    res = "保本浮动收益";
                    break;
                case 2:
                    res = "非保本浮动收益";
                    break;
                default:
                    res = "未知";
                    break;
            }
            return res;
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, CultureInfo language)
        {
            throw new NotImplementedException();
        }
    }

    public class RiskLevelToStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType,
        object parameter, CultureInfo language)
        {
            string res;
            switch ((int?)((double?)value))
            {
                case 0:
                    res = "保守型";
                    break;
                case 1:
                    res = "稳健型";
                    break;
                case 2:
                    res = "平衡型";
                    break;
                case 3:
                    res = "进取型";
                    break;
                case 4:
                    res = "积极型";
                    break;
                default:
                    res = "未知类型";
                    break;
            }
            return res;
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, CultureInfo language)
        {
            throw new NotImplementedException();
        }
    }

    public class InvestTypeToStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType,
        object parameter, CultureInfo language)
        {
            string res;
            switch ((byte?)value)
            {
                case 0:
                    res = "货币型";
                    break;
                case 1:
                    res = "债券型";
                    break;
                case 2:
                    res = "信托型";
                    break;
                case 3:
                    res = "股票型";
                    break;
                case 4:
                    res = "混合型";
                    break;
                default:
                    res = "未知类型";
                    break;
            }
            return res;
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, CultureInfo language)
        {
            throw new NotImplementedException();
        }
    }

    public class CurrencyToStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType,
        object parameter, CultureInfo language)
        {
            string res;
            switch ((byte?)value)
            {
                case 0:
                    res = "人民币";
                    break;
                case 1:
                    res = "美元";
                    break;
                case 2:
                    res = "欧元";
                    break;
                case 3:
                    res = "港币";
                    break;
                case 4:
                    res = "其他";
                    break;
                default:
                    res = "未知货币类型";
                    break;
            }
            return res;
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, CultureInfo language)
        {
            throw new NotImplementedException();
        }
    }

    public class TypeToStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType,
        object parameter, CultureInfo language)
        {
            string res;
            switch ((byte?)value)
            {
                case 0:
                    res = "开放式";
                    break;
                case 1:
                    res = "封闭式";
                    break;
                default:
                    res = "未知方式";
                    break;
            }
            return res;
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, CultureInfo language)
        {
            throw new NotImplementedException();
        }
    }

    public class InvestOrientToStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType,
        object parameter, CultureInfo language)
        {
            string res;
            switch ((byte?)value)
            {
                case 0:
                    res = "股票型";
                    break;
                case 1:
                    res = "债券型";
                    break;
                case 2:
                    res = "货币型";
                    break;
                case 3:
                    res = "混合型";
                    break;
                default:
                    res = "未知类型";
                    break;
            }
            return res;
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, CultureInfo language)
        {
            throw new NotImplementedException();
        }
    }

    public class StarToStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType,
        object parameter, CultureInfo language)
        {
            string res;
            switch((string)value)
            {
                case "/YFIN.View;component/Images/stars/5.png":
                    res = "非常吻合";
                    break;
                case "/YFIN.View;component/Images/stars/4.png":
                    res = "很吻合";
                    break;
                case "/YFIN.View;component/Images/stars/3.png":
                    res = "比较吻合";
                    break;
                case "/YFIN.View;component/Images/stars/2.png":
                    res = "有点吻合";
                    break;
                default:
                    res = "不是很吻合";
                    break;
            }
            return res;
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, CultureInfo language)
        {
            throw new NotImplementedException();
        }
    }

    public class BankToStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType,
        object parameter, CultureInfo language)
        {
            string res;
            string t = (string) value;
            if(t.Contains("工行") || t.Contains("工商"))
            {
                res = "/YFIN.View;component/Images/banklogos/gongshang.png";
            }
            else if (t.Contains("光大"))
            {
                res = "/YFIN.View;component/Images/banklogos/guangda.png";
            }
            else if (t.Contains("华夏"))
            {
                res = "/YFIN.View;component/Images/banklogos/huaxia.png";
            }
            else if (t.Contains("建行") || t.Contains("建设"))
            {
                res = "/YFIN.View;component/Images/banklogos/jianshe.png";
            }
            else if (t.Contains("交行") || t.Contains("交通"))
            {
                res = "/YFIN.View;component/Images/banklogos/jiaotong.png";
            }
            else if (t.Contains("农行") || t.Contains("农业"))
            {
                res = "/YFIN.View;component/Images/banklogos/nongye.png";
            }
            else if (t.Contains("浦发") || t.Contains("浦东"))
            {
                res = "/YFIN.View;component/Images/banklogos/pudong.png";
            }
            else if (t.Contains("什么"))
            {
                res = "/YFIN.View;component/Images/banklogos/shenme.png";
            }
            else if (t.Contains("深发") || t.Contains("深圳发展"))
            {
                res = "/YFIN.View;component/Images/banklogos/shenzhengfazhan.png";
            }
            else if (t.Contains("兴业"))
            {
                res = "/YFIN.View;component/Images/banklogos/xingye.png";
            }
            else if (t.Contains("招行") || t.Contains("招商"))
            {
                res = "/YFIN.View;component/Images/banklogos/zhaoshang.png";
            }
            else if (t.Contains("中行") || t.Contains("中国银行"))
            {
                res = "/YFIN.View;component/Images/banklogos/zhonghang.png";
            }
            else if (t.Contains("人行") || t.Contains("央行") || t.Contains("中国人民"))
            {
                res = "/YFIN.View;component/Images/banklogos/yanghang.png";
            }
            else
            {
                res = "/YFIN.View;component/Images/banklogos/buzhidao.png";
            }
            return res;
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, CultureInfo language)
        {
            throw new NotImplementedException();
        }
    }
}
